<template>
  <div class="assess">
    <Header></Header>
    <div class="assessMain">
      <p class="current-nav2">
        当前位置 :
        <router-link to="waitAssess2">首页</router-link>
        <i>></i>
        <a>{{planCompany}}应急预案评审</a>
        <i>></i>
        <a>评审意见汇总</a>
      </p>
      <div class="mianOut">
        <div class="mianInner1">
          <div class="assess-title1">
            <h3>评审意见汇总</h3>
          </div>
          <div class="table_title1">
            形式评审表
            <a v-if="allFlag1" @click="goDetailAll(1,'situationFlag')">形式评审汇总</a>
            <a style="background:#ccc;" v-else>形式评审汇总</a>
          </div>
          <el-table ref="multipleTable" class="mt60" :data="data1">
            <el-table-column type="index" align="center" label="序号" width="150"></el-table-column>
            <el-table-column prop="userName" label="评审专家" align="center" width="200"></el-table-column>
            <el-table-column label="身份" align="center">
              <template slot-scope="scope">{{scope.row.identity =='1' ? '组长' :'组员'}}</template>
            </el-table-column>
            <el-table-column prop="assess" label="形式评审" align="center">
              <template>形式评审表</template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="150">
              <template slot-scope="scope">
                <el-button class="detail-btn" @click="goDetail('1',scope.row.reviewId)">
                  <i class="el-icon-search">查看</i>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="table_title1">
            要素评审表
            <a v-if="allFlag2" @click="goDetailAll(2,'keyFlag')">要素评审汇总</a>
            <a style="background:#ccc;" v-else>要素评审汇总</a>
          </div>
          <el-table ref="multipleTable" class="mt60" :data="data2">
            <el-table-column type="index" align="center" label="序号" width="150"></el-table-column>
            <el-table-column prop="userName" label="评审专家" align="center" width="200"></el-table-column>
            <el-table-column label="身份" align="center">
              <template slot-scope="scope">{{scope.row.identity =='1' ? '组长' :'组员'}}</template>
            </el-table-column>
            <el-table-column prop="assess" label="要素评审" align="center">
              <template>要素评审表</template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="150">
              <template slot-scope="scope">
                <el-button class="detail-btn" @click="goDetail('2',scope.row.reviewId)">
                  <i class="el-icon-search">查看</i>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="table_title1">
            附件要素评审表
            <a v-if="allFlag3" @click="goDetailAll(3,'addFlag')">附件要素评审汇总</a>
            <a style="background:#ccc;" v-else>附件要素评审汇总</a>
          </div>
          <el-table ref="multipleTable" class="mt60" :data="data3">
            <el-table-column type="index" align="center" label="序号" width="150"></el-table-column>
            <el-table-column prop="userName" label="评审专家" align="center" width="200"></el-table-column>
            <el-table-column label="身份" align="center">
              <template slot-scope="scope">{{scope.row.identity =='1' ? '组长' :'组员'}}</template>
            </el-table-column>
            <el-table-column prop="assess" label="附件评审" align="center">
              <template>附件评审表</template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="150">
              <template slot-scope="scope">
                <el-button class="detail-btn" @click="goDetail('3',scope.row.reviewId)">
                  <i class="el-icon-search">查看</i>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="table_title1">
            个人评审意见表
            <a v-if="allFlag4" @click="goDetailAll(4,'ideaPop')">个人评审意见汇总</a>
            <a style="background:#ccc;" v-else>个人评审意见汇总</a>
          </div>
          <el-table ref="multipleTable" :data="data4">
            <el-table-column type="index" align="center" label="序号" width="150"></el-table-column>
            <el-table-column prop="userName" label="评审专家" align="center" width="200"></el-table-column>
            <el-table-column label="身份" align="center">
              <template slot-scope="scope">{{scope.row.identity =='1' ? '组长' :'组员'}}</template>
            </el-table-column>
            <el-table-column prop="assess" label="个人评审" align="center">
              <template>个人评审意见表</template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="150">
              <template slot-scope="scope">
                <el-button class="detail-btn" @click="getDetail2('4',scope.row.userId)">
                  <i class="el-icon-search">查看</i>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="aBtnBox">
            <input type="button" @click="goNext" value="下一步" />
          </div>
        </div>
      </div>
    </div>
    <Footer />
    <el-dialog title :visible.sync="ideaPop" width="80%">
      <div class="ideaMain" v-if='detailData5.length > 0'>
        <h2 class="ideaTitle">应急预案评审意见表</h2>
        <p class="comName">单位名称：{{companyName}}</p>
        <Table5 :data='detailData5' :signImg='signImg5' @sendRemark='acceptRemark' @sendSuggest='acceptSuggest'  @sendConsensus='acceptConsensus'   />
        <div class="clearfix">
          <a class="table_save" @click="savePersonAll">保存</a>
        </div>
      </div>
    </el-dialog>
    <el-dialog title :visible.sync="ideaPop2" width="80%">
      <div class="ideaMain"  v-if='detailData4.length > 0'>
        <h2 class="ideaTitle">应急预案评审意见表</h2>
        <p class="comName">单位名称：{{companyName}}</p>
         <Table4 :data='detailData4'  :suggest='suggest' :remark='remark' :signImg='signImg8' />
      </div>
    </el-dialog>
    <el-dialog title :visible.sync="situationFlag" width="80%">
      <div class="ideaMain" v-if='detailData1.length > 0'>
        <h2 class="ideaTitle ideaTable1">应急预案形式评审表</h2>
<Table1 :data='detailData1' />
      </div>
    </el-dialog>
    <el-dialog title :visible.sync="keyFlag" width="80%">
      <div class="ideaMain" v-if='list1.length > 0'>
         <Table2 :data1='list1' :data2='list2' :data3='list3' />
      </div>
    </el-dialog>
    <el-dialog title :visible.sync="addFlag" width="80%">
      <div class="ideaMain" v-if='detailData3.length > 0'>
        <h2 class="ideaTitle">应急预案附件要素评审表</h2>
       <Table3 :data='detailData3' />
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Table1 from '../examine2/common/table1'
import Table2 from '../examine2/common/table2'
import Table3 from '../examine2/common/table3'
import Table4 from '../examine2/common/table4'
import Table5 from '../examine2/common/table5'
import Header from "../common/header2";
import Footer from "../common/footer";
import config from "../../config.js";
export default {
  components: {
    Header,
    Footer,Table1,Table2,Table3,Table4,Table5
  },
  data() {
    return {
      planCompany: "",
      allFlag1: true,
      allFlag2: true,
      allFlag3: true,
      allFlag4: true,
      ideaPop2: false,
      autograph: "",
      nextFlag: true,
      situationFlag: false,
      keyFlag: false,
      addFlag: false,
      ideaPop: false,
      signImg1: "",
      signImg2: "",
      signImg3: "",
      signImg4: "",
      signImg5: "",
      remark5: "",
      companyName: "",
      consensus: "",
      radios: [1, 2, 3],
      data1: [],
      data2: [],
      data3: [],
      data4: [],
      detailData1: [],
      detailData2: [],
      detailData3: [],
      detailData4: [],
      detailData5: [],
      list1:[],
      list2:[],
      list3:[],
      varname: "",
      suggestAll: "",
      suggest:'',
      remark:'',
      signImg8: "",

    };
  },
  mounted() {
    var arr = [1, 2, 3, 4];
    arr.map(item => {
      this.getData(item);
      this.getAllFlag(item);
    });
    this.varname = localStorage.planname.split(".")[0];
    this.planCompany = localStorage.planCompany;
  },
  methods: {
      acceptSuggest(val){
      this.suggestAll=val
    },
     acceptRemark(val){
       this.remark5=val
    },
      acceptConsensus(val){
       this.consensus=val
    },
    goNext() {
      let flag = false;
      var arr = [1, 2, 3, 4];
      arr.map(item => {
        if (this["allFlag" + item]) {
          flag = true;
        }
      });
      if (!flag) {
        this.$router.push("assessedAlls2");
      } else {
        this.$message.warning("请汇总所有的评审表");
      }
    },
    getPersonAll() {
      let url = config.baseUrl + "emergency/v1.0/review/search";
      this.$axios
        .post(url, {
          planSummaryId: localStorage.planid,
          reviewType: 8
        })
        .then(res => {
          if (res.data.meta.success) {
            this.companyName = res.data.data.companyName;
            this.signImg5 = res.data.data.photoUrls;
            let arr = [];
            let str = "";
            if(res.data.data.opinions){
            res.data.data.opinions.map(item => {
              arr.push(JSON.parse(item.photo));
              str += item.opinion + `\n`;
            });
            }
            this.suggestAll = str;
            this.autograph = arr;
            res.data.data.list.map(item => {
              if (item.remarks) {
                this.remark5 = item.remarks;
              }
              item.opinion=str
              item.remarks=''
            });
            
            this.detailData5 = res.data.data.list;
          } else {
            if (res.data.meta.message != "暂无数据") {
              this.$message.warning(res.data.meta.message);
            }
          }
        });
    },
    savePersonAll() {
      if (this.suggestAll == "" || this.consensus == "") {
        this.$message.warning("专家建议不能为空");
      } else {
        let url = config.baseUrl + "emergency/v1.0/review/saveOne";
        let param = {
          consensus: this.consensus,
          opinion: this.suggestAll,
          remarks: this.remark5,
          reviewType: "8",
          autograph: JSON.stringify(this.autograph),
          summaryTemplateName: localStorage.planname,
          planSummaryId: localStorage.planid,
          userId: localStorage.userid
        };
        this.$axios.post(url, param).then(res => {
          if (res.data.meta.success) {
            this.$message.success(res.data.meta.message);
            this.ideaPop = false;
            this.allFlag4 = false;
          } else {
            this.$message.warning(res.data.meta.message);
          }
        });
      }
    },
    goDetailAll(n, flag) {
      if (this["allFlag" + n]) {
        if (n == 4) {
          this.getPersonAll();
          this[flag] = true;
        } else {
          this.reviewSummaryTabel(n, flag);
        }
      }
    },
    goDetail(n, id) {
      switch (n) {
        case "1":
          this.situationFlag = true;
          break;
        case "2":
          this.keyFlag = true;
          break;
        default:
          this.addFlag = true;
          break;
      }
      this.getDetail(n, id);
    },
    getAllFlag(n) {
      let url =
        config.baseUrl +
        "bsReview/v1.0/review/querySummaryType?planSummaryId=" +
        localStorage.planid;
      this.$axios.get(url).then(res => {
        if (res.data.meta.success) {
          if (res.data.data.length > 0) {
            res.data.data.map(item => {
              if (item.reviewType == 5) {
                this.allFlag1 = false;
              }
              if (item.reviewType == 6) {
                 this.allFlag2 = false;
              }
              if (item.reviewType == 7) {
                this.allFlag3 = false;
              }
              if (item.reviewType == 8) {
                this.allFlag4 = false;
              }
            });
          }
        } else {
          if (res.data.meta.message != "数据不存在") {
            this.$message.warning(res.data.meta.message);
          }
        }
      });
    },
    bubbleSort(array) {
      var i = 0,
        len = array.length,
        j,
        d;
      for (; i < len; i++) {
        for (j = 0; j < len; j++) {
          if (array[i].intOrder < array[j].intOrder) {
            d = array[j];
            array[j] = array[i];
            array[i] = d;
          }
        }
      }
      return array;
    },
    reviewSummaryTabel(n, flag) {
      let url = config.baseUrl + "bsReview/v1.0/review/reviewSummaryTabel";
      this.$axios
        .post(url, {
          planSummaryId: localStorage.planid,
          reviewTemplateName: localStorage.planname,
          reviewType: (n*1+4),
          userId: localStorage.userid
        })
        .then(res => {
          if (res.data.meta.success) {

if(res.data.data.list.length>0){
                    res.data.data.list.map((item,index)=>{
                      item.result=item.selectResult
                    })
                  }
           if(n==1){
                res.data.data.list.push({
                  reviewContent: res.data.data.url,
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "5",
                  flag:0,
                })
           }
           if(n==2){
              var obj = {
                    reviewContent:  res.data.data.url,
                    reviewItemOne: "评审专家签字",
                    reviewMethod: "",
                    tableType: "6",
                    flag:0,
                  }
                  this.list1 = res.data.data.list.splice(0,20)
                  this.list2 = res.data.data.list.splice(0,10)
                  this.list3 = res.data.data.list
               
                    this.list1.push({
                        reviewContent : '',
                        reviewItemOne: "注：“＊”代表应急预案的关键要素。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list2.push({
                      reviewContent: '',
                      reviewItemOne: "注：“＊”代表应急预案的关键要素。如果专项应急预案作为综合应急预案的附件，综合应急预案已经明确的要素，专项应急预案可省略。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list3.push({
                      reviewContent: '',
                      reviewItemOne: "注：“＊”代表应急预案的关键要素。现场处置方案落实到岗位每个人，可以只保留应急处置。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list1.push(obj)
                    this.list2.push(obj)
                    this.list3.push(obj)    

           }

           if(n==3){
              res.data.data.list.push({
                   reviewContent: '',
                   reviewItemOne: "注：附件根据应急工作需要而设置，部分项目可省略。",
                    reviewMethod: "",
                    tableType: "6",
                    flag:1,
                })
                res.data.data.list.push({
                  reviewContent: res.data.data.url,
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "7",
                  flag:0,
                })
           }




            this["detailData" + n] = this.bubbleSort(res.data.data.list);
            this["signImg" + n] = res.data.data.url;
            this[flag] = true;
            this["allFlag" + n] = false;
          } else {
            if (res.data.meta.message != "暂无数据") {
              this.$message.warning(res.data.meta.message);
            }
          }
        });
    },
    getDetail2(n, id) {
      this.ideaPop2 = true;
      let url = config.baseUrl + "emergency/v1.0/review/info";
      this.$axios
        .post(url, {
          planSummaryId: localStorage.planid,
          tableType: (n*1+4),
          userId: id
        })
        .then(res => {
          if (res.data.meta.success) {
            this.companyName = res.data.data.companyName;
             res.data.data.list.map((item)=>{
                      this.suggest = item.opinion
                      this.remark=item.remarks
                      this.signImg8 = [item.url]
                })
            this["signImg" + n] = res.data.data.list[0].url;
            this["detailData" + n] = res.data.data.list;
          } else {
            if (res.data.meta.message != "暂无数据") {
              this.$message.warning(res.data.meta.message);
            }
          }
        });
    },
    getDetail(n, id) {
      let url = config.baseUrl + "bsReview/v1.0/review/info?reviewId=" + id;
      this.$axios.get(url).then(res => {
        if (res.data.meta.success) {
          if(res.data.data.list.length>0){
                    res.data.data.list.map((item,index)=>{
                      item.result=item.selectResult
                    })
                  }
           if(n==1){
                res.data.data.list.push({
                  reviewContent: [res.data.data.autograph],
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "5",
                  flag:0,
                })
           }
           if(n==2){
              var obj = {
                    reviewContent:  [res.data.data.autograph],
                    reviewItemOne: "评审专家签字",
                    reviewMethod: "",
                    tableType: "6",
                    flag:0,
                  }
                  this.list1 = res.data.data.list.splice(0,20)
                  this.list2 = res.data.data.list.splice(0,10)
                  this.list3 = res.data.data.list
               
                    this.list1.push({
                        reviewContent : '',
                        reviewItemOne: "注：“＊”代表应急预案的关键要素。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list2.push({
                      reviewContent: '',
                      reviewItemOne: "注：“＊”代表应急预案的关键要素。如果专项应急预案作为综合应急预案的附件，综合应急预案已经明确的要素，专项应急预案可省略。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list3.push({
                      reviewContent: '',
                      reviewItemOne: "注：“＊”代表应急预案的关键要素。现场处置方案落实到岗位每个人，可以只保留应急处置。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list1.push(obj)
                    this.list2.push(obj)
                    this.list3.push(obj)    

           }

           if(n==3){
              res.data.data.list.push({
                   reviewContent: '',
                   reviewItemOne: "注：附件根据应急工作需要而设置，部分项目可省略。",
                    reviewMethod: "",
                    tableType: "6",
                    flag:1,
                })
                res.data.data.list.push({
                  reviewContent: [res.data.data.autograph],
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "7",
                  flag:0,
                })
           }

          this["signImg" + n] = res.data.data.autograph;
          this["detailData" + n] = res.data.data.list;
        } else {
          if (res.data.meta.message != "暂无数据") {
            this.$message.warning(res.data.meta.message);
          }
        }
      });
    },
    getData(n) {
      let url =
        config.baseUrl +
        "bsReview/v1.0/review/summaryList?planSummaryId=" +
        localStorage.planid +
        "&reviewType=" +
        (n+4);
      this.$axios.get(url).then(res => {
        if (res.data.meta.success) {
          this["data" + n] = res.data.data;
        } else {
          if (res.data.meta.message != "暂无数据") {
            this.$message.warning(res.data.meta.message);
          }
        }
      });
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='less'>
@import "../../../static/css/assess.less";
td.sign-word {
  img {
    float: left;
  }
  i {
    line-height: 36px;
    background: #edf4fe;
    padding: 0 15px;
    border-radius: 4px;
    color: #4080fe;
    cursor: pointer;
    float: left;
    border: 1px solid #edf4fe;
  }
  i:hover {
    border: 1px solid #4080fe;
  }
}

</style>
